package cn.edu.xmu.datamining.tangzk.mralgos.secondarysort;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

public class SecondarySortReducer extends
		Reducer<KeyPair, Text, IntWritable, Text> {
	protected void reduce(
			KeyPair key,
			java.lang.Iterable<Text> values,
			org.apache.hadoop.mapreduce.Reducer<KeyPair, Text, IntWritable, Text>.Context context)
			throws java.io.IOException, InterruptedException {
		StringBuilder sb = new StringBuilder();
		for (Text val : values) {
			sb.append(" ").append(key.getId2()).append(":")
					.append(val.toString());
		}
		context.write(new IntWritable(key.getId1()), new Text(sb.toString()));
	};
}
